var jsonList = {};
var page = 1;
var rows = 10;
var url ="/api/data/tag/special/list?page=";
var oZtid=1;
var lei="专题";
$.FreeTags('tags');
$(function (){
    $(".top_btn span").on('click',function (){
        $(this).addClass("on").siblings().removeClass("on");
    })
    $(".top_btn span").eq(0).on('click',function (){
        url = "/api/data/tag/special/list?page=";
        oZtid = 1;
        lei="专题";
        page = 1;
        rows = 10;
        getList(url);
    })
    $(".top_btn span").eq(1).on('click', function () {
        url = "/api/data/tag/article/list?page=";
        oZtid = 2;
        lei="文章";
        page = 1;
        rows = 10;
        getList(url);
    })
})
getList(url);
function getList(n) {
    $.ajax({
        url: baseNews + n + page + "&rows=" + rows,
        type: "get",
        data: {},
        success: function (res) {
            console.log(res, 666);
            if (res.code == 0) {
                var result = res.data;
                var list = result.list;
                console.log(list, 9999)
                var html = "";
                $("#page").paging({
                    pageNo: page,
                    totalPage: result.totalpage,
                    totalSize: result.totals,
                    callback: function (num) {
                        page = num;
                        getList(url);
                    }
                })
                $(".pd_bx").empty();
                $(list).each(function (index, key) {

                    html += `<tr>
                            <td><input type="checkbox" oid="${key.id}" class="arc_isc"/></td>
                            <td>${key.id}</td>
                            <td>${lei}</td>
                            <td>${key.tag}</td>
                            <td>${key.count}</td>
                            <td>
                                <span>查看</span>
                            </td>
                            <td>操作</td>
                        </tr>`;
                })
                $(".pd_bx").append(html);
            }
        }
    })
    //分页
}

$(function (){
    //删除
    $(".gx_del").on('click', function () {
        var delUrl="";
        if (oZtid == 1) {
            delUrl = "/api/data/tag/special/del?id=";
        } else {
            delUrl = "/api/data/tag/article/del?id=";
        }
        var numCount = 0;
        var ids = '';
        $(".arc_isc").each(function (index, key) {
            if ($(this).prop("checked") == true) {
                numCount++;
                ids = ids + $(this).attr("oid") + ',';
            }
        })
        console.log(numCount, 555);
        ids = ids.substring(0, ids.length - 1);
        console.log(ids)
        if (numCount >= 1) {
            //进行下一步
            zeroModal.confirm("确定要删除吗？", function () {
                //确定要推荐
                $.ajax({
                    url: baseNews + delUrl + ids,
                    type: "get",
                    data: {},
                    success: function (res) {
                        if (res.code == 0) {
                            location.reload();
                        } else {
                            zeroModal.alert('删除失败');
                        }
                    }
                })
            });
        } else {
            //遮罩层提示
            zeroModal.alert('请选择至少一篇文章');

        }
    })
    $(".bq_qx").on('click',function (){
        location.reload();
    })
    $(".bq_tab").hide();
    //开关
    $('.tab_add').on('click',function (){
        $(".zt_list").hide();
        $(".bq_tab").show();
        $('.show_title').hide();
    })
    $(".bq_qd").on('click',function (){
        var tabUrl="";
        var tags =[];
        $(".input_box a").each(function (index, key) {
            //tags = tags + $(this).find("span").html() + ',';
            tags.push($(this).find("span").html())
        })
        var jsonall={
            tags:tags
        };
        var result = JSON.stringify(tags);
        //zeroModal.loading(5);
        console.log(tags);
        if (oZtid == 1){
            tabUrl ="/api/data/tag/special/add";
        }else{
            tabUrl = "/api/data/tag/article/add";
        }
        if (tags.length<=0){
            zeroModal.alert("请输入标签");
        }
        $.ajax({
            url: baseNews + tabUrl,
            type: "post",
            headers: { 'Content-Type': 'application/json' },
            dataType: "json",
            data: result,
            success: function (res) {
                console.log(res, 666)
                if (res.code == 0) {
                    location.reload();
                } else {

                    zeroModal.alert(res.message);

                }
            }
        })
    })
})